<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page import="com.hnas.core.util.PropertyUtil"%>
<%@page import="com.hnas.core.dto.DataBean"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${pageTitle }</title>
<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath }/static/common/multiple/easyui.css"/>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/common/multiple/jquery.easyui.min.js"></script>
<script type="text/javascript">
(function($){ 

    $.fn.UIdialog = $.fn.dialog; /* 把jquery-ui的dialog另存为UIdialog */ 

})(jQuery)
</script>
</head>
<body>
	<!-- 标题 -->
	<div class="titleBar m_b_20">
		<div class="tit fl b_l_e74a5f">
			<h3 class="cn">${pageTitle }</h3>
			<span class="en">commodit mrch information</span>
		</div>
		<div class="fr"></div>
	</div>
	<!-- end 标题 -->

	<form method="post" action="${pageContext.request.contextPath }/backend/commodit/mrch" name="searchForm"  >
  	<input type="hidden" name="pageNo" value="${dto.pageNo}">
  	<input type="hidden" name="totalCount" value="${dto.totalCount}">
	<!-- 查询 -->
	<div class="box_03 p_20 m_b_20">
		<table class="tb_style02" width="100%">
	        <tr>
                <th style="width:130px;">每页显示</th>
               	<td>
               		<input type="text" style="width:30px;" name="pageSize" id="pageSize" value="${dto.pageSize}" style="width:100px;" class="input_style2"/>
                </td>
                
                <th style="width:130px;"></th>
               	<td>
               		<input style="width:110px;" class="btn_brown02 m_r_12" type="button" name="searchData" id="searchData" value="查  询">
               		<input style="width:110px;" class="btn_brown02 m_r_12" type="button" name="addData" id="addData" value="添  加">
                </td>
	         </tr>
		</table>
	</div> 
	<!-- end 查询 -->
				
</form>

<div class="m_b_20">
	<table class="tb_style05" width="100%" style="table-layout:fixed;">
		<thead>
		<tr>
			<c:forEach items="${beans}" var="o">
			<c:if test="${o.display && !o.hidden}"><th>${o.title}</th></c:if>
			</c:forEach>
			<th width="100">操作</th> 
		</tr>
		</thead>
		<tbody>
			<c:forEach items="${pg.list}" var="o">
			<tr>
				<c:forEach items="${beans}" var="o1">
					<c:if test="${o1.display && !o1.hidden}">
					<td style="word-wrap:break-word;"><%=String.valueOf(PropertyUtil.getValue(pageContext.getAttribute("o"),((DataBean)pageContext.getAttribute("o1")).getField())).replace("false","否").replace("true","是")%></td></c:if>
				
				</c:forEach>
				<td>
					<a href="#" class="c_3366cc btn editData" id="${o.id }">
					        查看
					</a>
					<a href="#" class="c_3366cc btn editDataDetail" id="${o.id }" >
					        详情
					</a>
				</td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
	<div class="searpage" align="right"><div>${pg.pageStr}</div></div><br/>
	
	
	<div class="editDataDiv" id="addDiv" title="添加商品商户信息" style="display:none;" autocomplete="off">
		<form action="#" id="addFm" method="post" name = "addFm" class="editFm">
			<table>
				<input type = "hidden" name = "id" id = "idInput" value="">
				<tr>
					<td>
						<label>商户名称：</label>
					</td>
					<td>
						<input class="easyui-combobox input_style2" width="198px;" name="mrchName" id="addMrchName">
					    <font color="red">*</font>
					</td>
				</tr>
				<tr>
					<td>
						<label>商户编号：</label>
					</td>
					<td>
						<input id="addMrchId" name="mrchId" value="" style="width:169px;" class="input_style2" readonly="true" >
					    <font color="red">*</font>
					</td>
				</tr>
				<tr>
					<td width="26%" align="right">商户地址</td>
					<td><input type="text" name="address" id="addressInput" style="width:200px" value=""/>
				</tr>
				<tr>
					<td width="26%" align="right">商户图片</td>
					<td>
						<input type = "hidden" name = "mrchPic" id="mrchPic" >
						<input type="file" name="mrchPicFile" id="mrchPicFile" style="width:200px" class="showContent" >
					</td>
				</tr>
			</table>
		</form>
	</div>
	
	
	
	<div class="editDataDiv" id="editDIV" title="${pageTitle}" style="display: none;" autocomplete="off">
		<form action="#" id="editFm" method="post" name="editFm" class="editFm" >
			<table >
				<c:forEach items="${beans}" var="o">
					<c:choose>
						<c:when test="${o.hidden}">
							<input type="hidden" name="${o.field}" id="deal${o.fieldId}" value="0">
						</c:when>
						<c:otherwise>
							<tr>
								<td width="26%" align="right"> 
									<label>${o.title}：</label>  
								</td>
								<c:if test="${o.tagType == 0}">
									<td> 
										<input type="text" name="${o.field}" id="deal${o.fieldId}" style="width:${o.length gt 0?o.length:200}px" <c:if test="${o.maxlength>0}">maxlength="${o.maxlength}"</c:if> <c:if test="${true == o.readonly}">readonly="readonly"</c:if>/>
										<c:if test="${not empty o.hint}">（${o.hint}）</c:if>
										<c:if test="${empty o.hint && o.dataType=='boolean'}">（1--是；0--否）</c:if>
										<c:if test="${!o.nullable}"><font color="red">*</font></c:if>
									</td>
								</c:if>
								<c:if test="${o.tagType == 1}">
									<td>
										<textarea name="${o.field}" id="deal${o.fieldId}" rows="3" style="width:${o.length gt 0?o.length:200}px" <c:if test="${o.maxlength>0}">maxlength="${o.maxlength}"</c:if> <c:if test="${true == o.readonly}">readonly="readonly"</c:if>></textarea>
										<c:if test="${not empty o.hint}">（${o.hint}）</c:if>
										<c:if test="${empty o.hint && o.dataType=='boolean'}">（1--是；0--否）</c:if>
										<c:if test="${!o.nullable}"><font color="red">*</font></c:if>
									</td>
								</c:if>
							</tr>
						</c:otherwise>
					</c:choose>
				</c:forEach>
				<tr>
	      			<td colspan="2">
	          			<p class="validateTips_deal" align="center"></p>
	      			</td>
	    		</tr>
			</table>
		</form>
	</div>
	
	
	
</div>
<%-- <script type="text/javascript" src="${pageContext.request.contextPath }/static/js/jquery.timepicker.js"></script> --%>
<script>
	function gotoJumpPage(){
		var jumpNum= $("#jumpNum").val();
		$("#search_page_size").val($("#id_page_size").val());
		gotoPage(jumpNum);
		return false;
	}
	$(function(){
		$("#searchData").click(function(){
			/** 校验输入页数是否非法  **/
			var pageSize=$("#pageSize").val();
			var reg = new RegExp("^[0-9]*$");
			if($.trim(pageSize)!=""){
				if(!reg.test($.trim(pageSize))){
					alert("每页显示数请输入非负整数");
	 				return false;
				}
			}
			if($.trim(pageSize)==""){
				alert("每页显示数不应许为空");
				return false;
			}
			doSubmit();
		});
		
	});
	
	$("#startDate").datepicker({
		dateFormat:'yy-mm-dd',
		changeYear: true,
		changeMonth: true,
		yearRange: "1900:2049" 
	});
	
	$("#endDate").datepicker({
		dateFormat:'yy-mm-dd',
		changeYear: true,
		changeMonth: true,
		yearRange: "1900:2049" 
	});	
	
	//编辑
	$(".editData").click(function(){
		var id = $(this).attr("id");
		$.ajax({
			url:"${pageContext.request.contextPath}/backend/commodit/showCommoditMrch/"+id,
			type: 'POST',
			error: function(XMLHttpRequest, textStatus, errorThrown){
				 $.dialog.alert({title:"查看",content:"加载数据异常。"});
			},
			success: function(data){
				fillDIV(data);
			}
		});
		$("#editDIV").UIdialog("open");
	});
	
	$("#addData").click(function(){
		$("#addDiv").UIdialog("open");
	});
	
	$(".editDataDetail").click(function(){
		var orderNo = $(this).attr("orderNo");
		var orderType = $(this).attr("orderType");
		window.location.href = "${pageContext.request.contextPath}/backend/order/searchDetail?orderNo="+orderNo+"&orderType="+orderType; 
	});
	
	function fillDIV(data){
		$("#dealid").val(data.id);
		<c:forEach items="${beans}" var="o">
			$("#deal${o.filterField}").val(data.${o.field});
		</c:forEach>
	}
	
	var editDivHeight = 550;
	var editDivWidth = 450;
	var isEditDivHeight = typeof myEditDivHeight == "undefined";
	var isEditDivWidth = typeof myEditDivWidth == "undefined";
	
	$("#editDIV").UIdialog({
		autoOpen : false,
		bgiframe: true, 
		height : isEditDivHeight?editDivHeight:myEditDivHeight,
		width : isEditDivWidth?editDivWidth:myEditDivWidth,
		modal : true,
		resizable :false,
		hide: '',
		show:'',
		zIndex:1000,
		close : function() {
		}
	});
	
	$("#addDiv").UIdialog({
		autoOpen : false,
		bgiframe: true, 
		height : isEditDivHeight?editDivHeight:myEditDivHeight,
		width : isEditDivWidth?editDivWidth:myEditDivWidth,
		modal : true,
		resizable :false,
		hide: '',
		show:'',
		zIndex:1000,
		buttons : {
			"提 交" : function() {
				$.ajax({
					url : "${pageContext.request.contextPath}/backend/commodit/addCommoditMrch",
					type : 'POST',
					data : {
						/* "id" : $("#primaryId").val() */ 	
						"name":$("#nameInput").val(),
						"address":$("#addressInput").val()
					},
					error : function(XMLHttpRequest, textStatus, errorThrown){
						hideMask();
						//$.dialog.alert({title:"保存",content:"保存异常",callback:"query();"});
						$.dialog.alert({title:"保存",content:"保存异常"});
					},
					success: function(data){
						hideMask();
						if(data.result==1) {
							$("#addDiv").UIdialog("close");					
							$.dialog.alert({title:"保存",content:"修改成功",callback:"query();"});
							clearAllData();
							//setTimeout("query();",1000);
						} else {
							//$.dialog.alert({title:"保存",content: data.errorMessage,callback:"query();"});	
							$.dialog.alert({title:"保存",content: data.errorMessage});	
						}
					}
				});
			},
			"取 消" : function() {
				$(".validateTips").text("");
				$(this).dialog("close");
				query();
			}
		},
		close : function() {
		}
	});
	
	$('#addMrchName').combobox({
	    url:'${pageContext.request.contextPath}/backend/generateMrchTwoCode/getMrchs',
	    method:'get',
	    valueField:'mrch_ID',
	    textField:'mrch_NAME',
	    panelHeight:'300',
	    multiple : false,
	    formatter: function (row) {
	        var opts = $(this).combobox('options');
	        return '<input type="checkbox" class="combobox-checkbox">' + row[opts.textField]
	    },
	    onShowPanel: function () {
	    	console.log(33333333);
	        var opts = $(this).combobox('options');
	        var target = this;
	        var values = $(target).combobox('getValues');
	        $.map(values, function (value) {
	            var el = opts.finder.getEl(target, value);
	            el.find('input.combobox-checkbox')._propAttr('checked', true);
	        })
	    },
	    onLoadSuccess: function () {
	        var opts = $(this).combobox('options');
	        var target = this;
	        var values = $(target).combobox('getValues');
	    	console.log(opts);
	        $.map(values, function (value) {
	            var el = opts.finder.getEl(target, value);
	            el.find('input.combobox-checkbox')._propAttr('checked', true);
	        })
	    },
	    onSelect: function (row) {
	    	console.log(1111111111111);
	    	 $('#addMrchId').val("");
	        var opts = $(this).combobox('options');
	        var el = opts.finder.getEl(this, row[opts.valueField]);
	        el.find('input.combobox-checkbox')._propAttr('checked', true);
	        var mrchId = row.mrch_ID;
	        $('#addMrchId').val(mrchId);
	        $('#addTerminalNo').combobox('clear');
	        $('#addTerminalNo').combobox('loadData', {});
	        var urlTerminalNo = '${pageContext.request.contextPath }/backend/generateMrchTwoCode/getTerminalNo?mrchId=' + mrchId;
	        $('#addTerminalNo').combobox('reload', urlTerminalNo);
	    },
	    onUnselect: function (row) {
	    	console.log(000000000);
	        var opts = $(this).combobox('options');
	        var el = opts.finder.getEl(this, row[opts.valueField]);
	        $('#addMrchId').val("");
	        el.find('input.combobox-checkbox')._propAttr('checked', false);
	        $('#addTerminalNo').combobox('clear');
	    }
	});
	
</script>
</body>
</html>